home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / themous.com / MOUSTEXT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1991-01-02  |  6.1 KB  |  228 lines

  1. Program MouseText;
  2.  
  3. (*                                                   *)
  4. (*          An Example Program for TheMouse          *)
  5. (*      A Turbo Pascal Mouse Unit by Kevin Kwast     *)
  6. (*                                                   *)
  7.  
  8. Uses Crt, Dos, TMouse5;    {Change to TMouse4 if using Turbo Pascal 4}
  9.  
  10. Var
  11.    tmInit: TheMouseInitType;     {These types are in TheMouse}
  12.    tmEvent: TheMouseEventType;
  13.  
  14.    Done, DrawAgain: Boolean;
  15.  
  16.    OrigTextCursor: Word;
  17.  
  18. (***  Here is the event handler..  ***)
  19.  
  20. {$F+}         { Far Calls for Event Handler }
  21.  
  22. Procedure Event(Flags, CS, AX, BX, CX, DX, SI, DI, DS, ES, BP: Word);
  23.  
  24. {This will be called by the mouse driver, and must have this format}
  25. Interrupt;
  26.  
  27. Begin
  28.      tmEvent.EventMask := AX;
  29.      tmEvent.ButtonStatus := BX;
  30.      tmEvent.Column := CX;
  31.      tmEvent.Row := DX;
  32.  
  33.      Inline (            { exit for far return to mouse device driver }
  34.       $8B/$E5/     { Mov SP,BP }
  35.       $5D/         { Pop BP }
  36.       $07/         { Pop ES }
  37.       $1F/         { Pop DS }
  38.       $5F/         { Pop DI }
  39.       $5E/         { Pop SI }
  40.       $5A/         { Pop DX }
  41.       $59/         { Pop CX }
  42.       $5B/         { Pop BX }
  43.       $58/         { Pop AX }
  44.       $CB );       { RETF }
  45. End;
  46.  
  47. {$F-}
  48.  
  49. Procedure SaveTextCursor;
  50. Var Regs: Registers;
  51. Begin
  52.      Regs.AH:=3;
  53.      Intr($10, Regs);
  54.      OrigTextCursor:=Regs.CX;
  55. End;
  56.  
  57. Procedure OffTextCursor;
  58. Var Regs: Registers;
  59. Begin
  60.      Regs.AH:=1;
  61.      Regs.CX:=$0D0D;
  62.      Intr($10, Regs);
  63. End;
  64.  
  65. Procedure RestoreTextCursor;
  66. Var Regs: Registers;
  67. Begin
  68.      Regs.AH:=1;
  69.      Regs.CX:=OrigTextCursor;
  70.      Intr($10, Regs);
  71. End;
  72.  
  73. Function TextX(MousX: Word) : Byte;
  74. Begin
  75.      TextX:=(MousX div 8) + 1;
  76. End;
  77.  
  78. Function TextY(MousY: Word) : Byte;
  79. Begin
  80.      TextY:=(MousY div 8) + 1;
  81. End;
  82.  
  83. Procedure DoDemo;
  84. Begin
  85.      DrawAgain:=True;        {Tells Main to redraw after running this}
  86.      tmCursor(False);
  87.      ClrScr;                 {See what happens when you don't do this}
  88.      tmCursor(True);
  89.      TextColor(7);
  90.      GotoXY(31,25);
  91.      Write('Click Right to Exit');
  92.      GotoXY(18,2);
  93.      Write('TheMouse makes it easy to handle the mouse!');
  94.      GotoXY(15,3);
  95.      Write('Click the left button to put a star on the screen.');
  96.  
  97.      tmRowRange(25,190);  {Don't let mouse onto text}
  98.  
  99.      TextColor(12);   {Star will be light red}
  100.  
  101.      Repeat
  102.            tmEvent.EventMask:=0;
  103.            REPEAT UNTIL tmEvent.EventMask <> 0;
  104.  
  105.            If (tmEvent.EventMask and $4 <> 0) then
  106.            Begin
  107.                 GotoXY(TextX(tmEvent.Column), TextY(tmEvent.Row));
  108.                 tmCursor(False);
  109.                 Write('*');      {Again, this is necessary}
  110.                 tmCursor(True);
  111.            End;      { If left button released, put a star.. }
  112.  
  113.      Until (tmEvent.EventMask and $10 <> 0);  {Stop when right released}
  114.  
  115.      tmRowRange(0,199);
  116. End;
  117.  
  118. Procedure DoInfo;
  119. Begin
  120.      DrawAgain:=True;        {Tells Main to redraw after running this}
  121.      tmCursor(False);
  122.      ClrScr;
  123.      tmCursor(True);
  124.      GotoXY(5,3);
  125.      Write('TheMouse provides routines for text and graphics both.');
  126.      GotoXY(5,5);
  127.      Write('The perfect routines for your Turbo Pascal toolbox!');
  128.      GotoXY(21,20);
  129.      Write('> Click Right Here to Go Back to Main <');
  130.      REPEAT      {Sit in Loop}
  131.      UNTIL ((tmEvent.EventMask and $10 <> 0)
  132.            and (TextY(tmEvent.Row) = 20)
  133.            and (TextX(tmEvent.Column) in [21..59]));
  134. End;
  135.  
  136. Procedure DoHelp;
  137. Begin
  138.      DrawAgain:=True;        {Tells Main to redraw after running this}
  139.      tmCursor(False);
  140.      ClrScr;
  141.      tmCursor(True);
  142.      GotoXY(5,8);
  143.      Write('Move onto an option the same way you chose this to go to that section.');
  144.      GotoXY(15,10);
  145.      Write('Now click left in the box to exit    -->      [ ]');
  146.      REPEAT      {Sit in Loop}
  147.      UNTIL (tmEvent.EventMask and $4 <> 0) and (TextX(tmEvent.Column) = 62);
  148. End;
  149.  
  150. Procedure DoQuit;
  151. Var X: Byte;
  152. Begin
  153.      DrawAgain:=True;        {Tells Main to redraw after running this}
  154.      tmCursor(False);
  155.      ClrScr;
  156.      tmCursor(True);
  157.      GotoXY(27,25);
  158.      Write('Click Right on your Choice');
  159.      GotoXY(26,4);
  160.      Write('Do you want to quit?');
  161.      GotoXY(48,4);
  162.      TextColor(14);
  163.      Write('YES  NO');
  164.  
  165.      REPEAT
  166.        X:=TextX(tmEvent.Column);
  167.      UNTIL (tmEvent.EventMask and $10 <> 0) and (X in [48..50,53,54]);
  168.  
  169.      If X in [48..50] then Done:=True;
  170. End;
  171.  
  172.       (*  This program is very rough, and is just meant to    *)
  173.       (*  give you an idea how to use TheMouse in text mode.  *)
  174.  
  175. Begin
  176.      tmReset(tmInit);
  177.      If NOT tmInit.Exists then Begin
  178.                                     WriteLn('Mouse driver not found.');
  179.                                     Halt;
  180.                                End;
  181.  
  182.      SaveTextCursor;
  183.      OffTextCursor;
  184.  
  185.      tmTextCursor(0, 0, $0EFE); {Sets cursor to Character FE, Attribute E}
  186.      tmTask($17, seg(Event), ofs(Event)); {Trap Left & Right Button Releases}
  187.                                               { Also left button press }
  188.  
  189.      Done:=False;
  190.  
  191.      Repeat
  192.  
  193.      tmCursor(False);
  194.      ClrScr;
  195.      TextColor(14);
  196.      GotoXY(18,1);
  197.      Write('Demo         Info         Help         Quit');
  198.      TextColor(7);
  199.      GotoXY(24,25);
  200.      Write('Click Left Button on your Choice');
  201.  
  202.      tmCursor(True);
  203.  
  204.      DrawAgain:=False;
  205.      Repeat
  206.            tmEvent.EventMask:=0;
  207.            REPEAT UNTIL tmEvent.EventMask <> 0;
  208.            CASE tmEvent.EventMask of
  209.              $04,    {Left Button or Left with Motion}
  210.              $05: If TextY(tmEvent.Row) = 1 then
  211.                     Case TextX(tmEvent.Column) of
  212.                      17..22: DoDemo;
  213.                      30..35: DoInfo;
  214.                      43..48: DoHelp;
  215.                      56..61: DoQuit;
  216.                     End;
  217.            END;
  218.      Until DrawAgain;
  219.  
  220.      Until Done;
  221.  
  222.      tmReset(tmInit);          { Re-initialize mouse.. Must do this! }
  223.                    { Otherwise, the task will cause the computer to hang! }
  224.  
  225.      RestoreTextCursor;
  226.      ClrScr;
  227.      End.
  228.